-- The user must supply a definition f(x) and x1,x2 values that bracket the root. The root is found to within ±tol (default setting 1e-7).
-- Technically the sign of f(x) should be different at x1 and at x2 (this guarantees there is at least one root between x1 and x2) but this routine will usually converge as long as there is a root somewhere near x1 or x2.
-- example
f(x) = x^3 - 2*x
plot f(X)
Xmin=-2; Xmax=2
r1:=root(-2,-1), r1:-1.414
r2:=root(-1,1), r2:0.000
r3:=root(1,2), r3:1.414
plot {{r1,r2,r3},{0,0,0}}
--------------------
-- This routine uses the "false position" algorithm. The next guess is obtained by finding x at the zero crossing of a line drawn between the previous guesses.